|
![](/i/fill.gif) |
>> DBL x = 2.0;
>> becomes
>> DBL x = (DBL) 2.0;
>>
>> Is there anything unreasonable or dangerous about doing this?
>
>It is unreasonable: DBL x = 2.0; is c acompletly legal and *well* readable
>statement. DBL x = (DBL) 2.0 is less readable.
But the meaning is more precise. I think the benefit of clarity and
portability outweigh your concern - but that's entirely my opinion.
While the first line says "I want 2.0 assigned to x", the second says
"I knowingly want 2.0 converted to a DBL, and assigned to x".
For example, if you use a float as an intermediate result, treat it as a
double later, and wonder why you're not getting the expected precision -
the explicit cast will be something of a clue. Your preference is
to be oblivious to truncation.
It's a fine point, but I think it is more than just a platform/compiler
quirk - in this case Microsoft have done something for a sound
technical reason. (I wish they'd do so more often!)
Post a reply to this message
|
![](/i/fill.gif) |